`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    12:14:13 02/23/2014 
// Design Name: 
// Module Name:    vga 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
  module vga(	clock, 
				red,
				green,
				blue,
				HS,
				VS,
				enable1,
				enable2,
				enable3,
				enable4,
				enable5
				);
				
				//input enable2;
				input enable1,enable2,enable3,enable4,enable5;
				input wire clock;
			   output reg [2:0] red;
				output reg [2:0] green; 
				output  reg [1:0] blue;
				//reg [40:0] count=0;
				//reg clk60=0;
				output HS;
				output VS;
				wire clk_new;
				wire signed [10:0] hcounter,vcounter;
				wire blank;
				//wire [12:0] addra;
				//wire [7:0] data;
				//wire [14:0] addrb;
				//wire [7:0] data1;
				//wire [14:0] addrc;
				//wire [7:0] data2;
				//wire [14:0] addrd;
				//wire [7:0] data3;
				//wire [10:0] addre;
				//wire [7:0] data4;
				//wire [11:0] addrf;
				//wire [7:0] data5;
				//wire [10:0] addrg;
				//wire [7:0] data6;
				//wire [11:0] addrh;
				//wire [7:0] data7;
				//wire [11:0] addri;
				//wire [7:0] data8;
				//wire [11:0] addrj;
				//wire [7:0] data9;
				//reg signed [11:0]  Xpos, Xposnext, Xposnext1, Xposnext2;
				wire vgadisp1, vgadisp2, vgadisp3, vgadisp4, vgadisp5, vgadisp6, vgadisp7, vgadisp8, vgadisp9, vgadisp10;
				/*initial begin
				Xpos<=0;
				Xposnext<=234;
				Xposnext1<=468;
				Xposnext2<=702;
				end
				wire sprite1,sprite2,sprite3, sprite4, sprite5, sprite6, sprite7,sprite8,sprite9,sprite10, sprite11;
				assign sprite1=hcounter>=9 && hcounter<58 && vcounter>=50 && vcounter<89;
				assign sprite2=(hcounter>=Xpos && hcounter<Xpos+230 && vcounter>=321 && vcounter<479) || 
				(hcounter>=Xposnext && hcounter<Xposnext+230 && vcounter>=321 && vcounter<479)  ||
				(hcounter>=Xposnext1 && hcounter<Xposnext1+230 && vcounter>=321 && vcounter<479) ||
				(hcounter>=Xposnext2 && hcounter<Xposnext2+230 && vcounter>=321 && vcounter<479);
				assign sprite3=hcounter>=530 && hcounter<558 && vcounter>=193 && vcounter<208;
				assign sprite4=hcounter>=248 && hcounter<297 && vcounter>=112 && vcounter<156;
				assign sprite5=hcounter>=9 && hcounter<62 && vcounter>=263 && vcounter<310;
				assign sprite6=hcounter>=99 && hcounter<148 && vcounter>=100 && vcounter<142;
				assign sprite7=hcounter>=200 && hcounter<258 && vcounter>=100 && vcounter<143;
				assign sprite8=hcounter>=9 && hcounter<51 && vcounter>=80 && vcounter<111;
				assign sprite9 =hcounter>=120 && hcounter<168 && vcounter>=200 && vcounter<242;
				assign sprite10=hcounter>=9 && hcounter<60 && vcounter>=120 && vcounter<169;
				assign sprite11= hcounter>=120 && hcounter<169 && vcounter>=180 && vcounter<229;
				
				*/
				slowclk1 v1( clock, clk_new);
				vga_controller v2(clk_new,HS,VS,hcounter,vcounter,blank);
				/*addrcalc v3(enable1,hcounter, vcounter,blank,addra);
				mc v4(clk_new,addra,data);
				//mix v4(clk_new,addra,data);
				background_calc v5(Xpos,enable1,hcounter,vcounter,blank,addrb,Xposnext,Xposnext1, Xposnext2);
				backgrnd v6(clk_new,addrb,data1);
				addrcal_enemy1 v7(enable1,hcounter, vcounter,blank,addrc);
				e1 v8(clk_new,addrc,data2);
				addrcal_enemy2 v9(enable1,hcounter, vcounter,blank,addrd);
				e2 v10(clk_new,addrd,data3);
				addrcalc_coll v11(enable1,hcounter, vcounter,blank,addre);
				collision v13(
  .clka(clk_new), // input clka
  .addra(addre), // input [10 : 0] addra
  .douta(data4) // output [7 : 0] douta
);
				addrcal_enemy3 e3(enable1,hcounter, vcounter,blank,addrf);
				level2e e4(clk_new,addrf,data5);
				addrcal_enemy4 e5(enable1,hcounter, vcounter,blank,addrg);
				enemy4 e6(clk_new,addrg,data6);
				addrcal_enemy5 e7(enable1,hcounter, vcounter,blank,addrh);
				enemy5 e8(clk_new,addrh,data7);
				addrcal_enemy7 e9(enable1,hcounter, vcounter,blank,addri);
				enemy7 e10(clk_new,addri,data8);
				addrcal_enemy8 e11(enable1,hcounter, vcounter,blank,addrj);
				enemy8 e12(clk_new,addrj,data9);*/
				bulletdisplay e13(enable1, enable2, enable3,enable4,enable5,vgadisp1, vgadisp2, vgadisp3, vgadisp4, vgadisp5, vgadisp6, vgadisp7,vgadisp8, vgadisp9, vgadisp10, hcounter, vcounter,blank);


always@(posedge clk_new) begin

/*if(count==222500) begin
count<=0;
clk60<=~clk60; end
else
count<=count+1;

*/

//if(enable1) begin
/*if(sprite1)
{red,green,blue}=data;
else if(sprite2)
{red,green,blue}=data1;
else if(sprite3)
{red,green,blue}=data;
else if(sprite4)
{red,green,blue}=data2;
else if(sprite5)
{red,green,blue}=data3;
else if(sprite6)
{red,green,blue}=data4;
else if(sprite7)
{red,green,blue}=data5;
//end
else if(sprite8)
{red,green,blue}=data6;
else if(sprite9)
{red,green,blue}=data7;

else if(sprite10)
{red,green,blue}=data8;
else if(sprite11)
{red,green,blue}=data9;*/
 if(/*vgadisp1 || vgadisp2 || vgadisp3 || vgadisp4 || vgadisp5 ||*/ (vgadisp6 && enable1) || (vgadisp7 && enable2) || (vgadisp8 && enable3) || (vgadisp9 && enable4) || (vgadisp10 && enable5)) begin
red=3'b111;
green=3'b000;
blue=2'b00;
end

/*else if(enable2) begin
if(vgadisp7) begin
red=3'b111;
green=3'b000;
blue=2'b00;
end
end
else if(enable3) begin
if(vgadisp8) begin
red=3'b111;
green=3'b000;
blue=2'b00;
end
end
else if(enable4) begin
if(vgadisp9) begin
red=3'b111;
green=3'b000;
blue=2'b00;
end
end
else if(enable5) begin
if(vgadisp10) begin
red=3'b111;
green=3'b000;
blue=2'b00;
end
end*/
else begin
red=3'b000;
green=3'b000;
blue=2'b00;
end


end





/*always@(posedge clk60) begin


Xpos<=Xpos-2;
Xposnext<=Xposnext-2;
Xposnext1<=Xposnext1-2;
Xposnext2<= Xposnext2-2;

if(Xpos<-234)
Xpos<=640;
else if(Xposnext<-234)
Xposnext<=640;
else if(Xposnext1<-234)
Xposnext1<=640;
else if(Xposnext2<-234)
Xposnext2<=640;



end*/
endmodule


